﻿<?php  
class ControllerCommonHome extends Controller {
	public function index() {
	
		$this->document->setTitle('Whoslab');
		$this->document->setDescription('Whoslab');

		$this->data['heading_title'] = 'Whoslab';
		
		$this->data['link_message']=$this->url->link('page/message');
		$this->data['myplan']=$this->url->link('myplan/login');
		
		$this->getVisit();

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/home.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/common/home.tpl';
		} else {
			$this->template = 'default/template/common/home.tpl';
		}
		
		$this->children = array(
			'common/footer',
			'common/header'
		);
										
		$this->response->setOutput($this->render());
	}
	
	private function getVisit(){
	
			if (empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {  
				$myip = $_SERVER['REMOTE_ADDR'];  
			} else {  
				$myip = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);  
				$myip = $myip[0];  
			}  
			
			$data=array();
			$data["ip"]=$myip;
			
			$this->load->model("page/common");
			
			$this->model_page_common->saveVisit($data);
			
			$row=$this->model_page_common->getVisitsNum();
			
			$this->data["visitsnum"]=$row["COUNT(*)"];
	}
}
?>
